/**
 * 
 */
package com.google.code.sip.ucenter.ws.provider;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.Provider;

import com.google.code.sip.core.utils.CollectionUtils;
import com.google.code.sip.ucenter.ws.dto.UserProfileDto;

/**
 * @author Liuye
 * 
 */
@Provider
@Produces( { "application/x-www-form-urlencoded", "*/*" })
@Consumes( { "application/x-www-form-urlencoded", "*/*" })
public class UserProfileDtoReader extends DtoReader<UserProfileDto> {
	private static final String PRIVACY_PARAM_PREFIX = "#privacy#";

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.code.sip.ucenter.ws.provider.DtoReader#toEntity
	 * (java.util.Map)
	 */
	@Override
	protected UserProfileDto toDto(Map<String, String> map)
			throws IllegalAccessException, InvocationTargetException {
		UserProfileDto profileDto = super.toDto(map);
		// 获取属性保密设置,保密设置参数名必须以#privacy#为前缀
		Map<String, String> privacyOptions = CollectionUtils
				.getSubMapStartingWith(map, PRIVACY_PARAM_PREFIX);
		if (privacyOptions != null && !privacyOptions.isEmpty()) {
			for (Map.Entry<String, String> entry : privacyOptions.entrySet()) {
				String name = entry.getKey();
				String value = entry.getValue();
				profileDto.addPrivacyOption(name, value);
			}
		}
		return profileDto;
	}

}
